//
//  TxMapCompatible.swift
//  TencentMap
//
//  Created by 吴非 on 2022/5/19.
//

import UIKit

public typealias TxLocationResponseHandler = (TxMapMapper?) -> Void
// 地图协议
public protocol TxMapCompatible: AnyObject {
    /// 定位
    func gps_location(isModality: Bool, trigger: @escaping TxLocationResponseHandler)
    
}

// MARK: - 扩展控制器
public extension TxMapCompatible where Self: UIViewController {
    
    func gps_location(isModality: Bool = true, trigger: @escaping TxLocationResponseHandler) {
        TxMapHelper.isAuthorization(controller: self) { [weak self] isValue in
            guard let wkThis = self else { return }
            let controller = TxMapViewController()
            controller.isModalityValue = isModality
            controller.completionTrigger = trigger
            if isModality {
                let tmpNav = UINavigationController(rootViewController: controller)
                tmpNav.navigationBar.isTranslucent = false
                tmpNav.view.backgroundColor = UIColor.white
                tmpNav.modalPresentationStyle = .fullScreen
                wkThis.navigationController?.present(tmpNav, animated: true, completion: nil)
            } else {
                wkThis.navigationController?.pushViewController(controller, animated: true)
            }
        }
    }
}
